package com.fanco.learn_datastruct_leetcode.designpattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qiaowang 2022/2/15
 * 描述
 */
// University 就是Composite, 可以管理College
public class University extends OrganizationComponent{
    public University(String name, String desc) {
        super(name, desc);
    }

    List<OrganizationComponent> organizationComponentList = new ArrayList<OrganizationComponent>();

    @Override
    protected void print() {
        // print方法就是 输出university 包含的学院
        System.out.println("====" + getName() + "====");
        for (OrganizationComponent component : organizationComponentList) {
            component.print();
        }
    }

    /**
     * 重写add方法
     */
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        System.out.println("University的add方法");
        organizationComponentList.add(organizationComponent);
    }

    /**
     * 重写remove方法
     * @param organizationComponent
     */
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        System.out.println("University的remove方法");
        organizationComponentList.remove(organizationComponent);
    }
}
